<template>
  <el-form :model="form" label-width="120px">
    <el-form-item label="课程代码">
      <el-input v-model="form.course_code" />
    </el-form-item>
      <el-form-item label="课程名称">
        <el-input v-model="form.course_name" />
      </el-form-item>
      <el-form-item label="课程人数">
        <el-input v-model="form.course_number" disabled/>
      </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm() ">确认修改</el-button>
      <el-button @click="closeDialog() ">取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>

export default {
  props: {
    currentCourse: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      form: {
        course_code: '',
        course_name: '',
        course_number: 0,
      },

    };
  },
  methods: {
    submitForm() {
      this.$emit('submit-form',this.form);
    },
    closeDialog() {
      this.$emit('close-dialog');
    },
  },
  watch: {
    // 监听父组件传入的currentStudent变化
    currentCourse: {
      immediate: true,
      handler(newVal) {
        if (newVal) {
          // 将父组件传入的学生数据填充到表单中
          this.form = {
            course_code: newVal.course_code,
            course_name: newVal.course_name,
            course_number: newVal.course_number,
          }
        }
      }
    }
  },
};
</script>
